//
//  ICMProxySearchViewCell.m
//  ICrEAM
//
//  Created by Cty on 2016/11/09.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMProxySearchViewCell.h"
@interface ICMProxySearchViewCell()
@property (nonatomic,copy) UILabel *assistantName;//服务顾问名称
@property (nonatomic,copy) UILabel *assistantPhone;//服务顾问手机

@property (nonatomic,copy) UILabel *plateNum;//车牌号
@property (nonatomic,copy) UILabel *creatDate;//创建时间

@property (nonatomic,copy) UILabel *proxyType;//委托书类型
@property (nonatomic,copy) UILabel *proxyID;//委托书id

@property (nonatomic,copy) UILabel *carType;//车型

@property (nonatomic,copy) UILabel *customerName;//顾客名称
@property (nonatomic,copy) UILabel *customerPhone;//顾客手机

@property (nonatomic,copy) UIButton *btnPreview;//预览按钮


@end

@implementation ICMProxySearchViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (UILabel *)assistantName{
    
    if(!_assistantName){
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(ActualWidth(30), ActualHeight(20), ActualWidth(40), ActualHeight(40))];
        imageView.image = [UIImage imageNamed:Appointment_Consultant];
        
        _assistantName = [[UILabel alloc]initWithFrame:CGRectMake(imageView.rightEdge+10, ActualHeight(10),ActualWidth(145), ActualHeight(34))];
        _assistantName.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _assistantName.textAlignment = NSTextAlignmentLeft;
        
        _assistantName.textColor = Color(0x000000);
        
        [self addSubview: imageView];
        [self addSubview: _assistantName];

        //横的分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, ActualHeight(95)-1, ScreenWidth, 1)];
        view.backgroundColor = [UIColor whiteColor];
        
        [self addSubview:view];
        
    }
    return _assistantName;
    
}
- (UILabel *)assistantPhone{
    if(!_assistantPhone){
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(ActualWidth(30), self.assistantName.bottomEdge, ActualWidth(40), ActualHeight(40))];
        imageView.image = [UIImage imageNamed:Appointment_Consultant];
        _assistantPhone = [[UILabel alloc]initWithFrame:CGRectMake(imageView.rightEdge+10, self.assistantName.bottomEdge,ActualWidth(145), ActualHeight(34))];
        _assistantPhone.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _assistantPhone.textAlignment = NSTextAlignmentLeft;
        
        _assistantPhone.textColor = Color(0x666666);
        
        [self addSubview: _assistantPhone];
        
    }
    return _assistantPhone;

}

- (UILabel *)plateNum{
    if(!_plateNum){
        _plateNum = [[UILabel alloc]initWithFrame:CGRectMake(self.assistantPhone.rightEdge+10, self.assistantName.y,ActualWidth(135), ActualHeight(34))];
        _plateNum.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _plateNum.textAlignment = NSTextAlignmentCenter;
        
        _plateNum.textColor = Color(0x000000);
        
        [self addSubview: _plateNum];
        
        //分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.assistantPhone.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        
        [self addSubview:view];
    
    }
    return _plateNum;

}
- (UILabel *)creatDate{
    if(!_creatDate){
        
        _creatDate = [[UILabel alloc]initWithFrame:CGRectMake(self.assistantPhone.rightEdge+10, self.plateNum.bottomEdge,ActualWidth(135), ActualHeight(34))];
        _creatDate.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _creatDate.textAlignment = NSTextAlignmentCenter;
        
        _creatDate.textColor = Color(0x666666);
        
        [self addSubview: _creatDate];
    
    }
    return _creatDate;

}
- (UILabel *)proxyType{
    
    if(!_proxyType){
        _proxyType = [[UILabel alloc]initWithFrame:CGRectMake(self.creatDate.rightEdge+10, self.assistantName.y,ActualWidth(145), ActualHeight(34))];
        _proxyType.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _proxyType.textAlignment = NSTextAlignmentCenter;
        
        _proxyType.textColor = Color(0x000000);
        
        [self addSubview: _proxyType];
    }
    return _proxyType;
}

- (UILabel *)proxyID{
    
    if(!_proxyID){
        
        _proxyID = [[UILabel alloc]initWithFrame:CGRectMake(self.creatDate.rightEdge+10, self.proxyType.bottomEdge,ActualWidth(145), ActualHeight(34))];
        _proxyID.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _proxyID.textAlignment = NSTextAlignmentCenter;
        
        _proxyID.textColor = Color(0x666666);
        
        [self addSubview: _proxyID];
        
        //分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.creatDate.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        
        [self addSubview:view];
        
    }
    return _proxyID;
}
- (UILabel *)carType{
    if(!_carType){
    
        _carType = [[UILabel alloc]initWithFrame:CGRectMake(self.proxyID.rightEdge+10, ActualHeight(23),ActualWidth(135), ActualHeight(34))];
        _carType.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _carType.textAlignment = NSTextAlignmentCenter;
        
        _carType.textColor = Color(0x000000);
        
        [self addSubview: _carType];
        _carType.centerY = ActualHeight(95)/2.0;
        
        //分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.proxyID.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        
        [self addSubview:view];
        
    }
    return _carType;

}
- (UILabel *)customerName{
    
    if(!_customerName){
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.carType.rightEdge+ActualWidth(20), ActualHeight(20), ActualWidth(40), ActualHeight(40))];
        imageView.image = [UIImage imageNamed:Appointment_Customer];
        
        _customerName = [[UILabel alloc]initWithFrame:CGRectMake(imageView.rightEdge+10, self.assistantName.y,ActualWidth(145), ActualHeight(34))];
        _customerName.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _customerName.textAlignment = NSTextAlignmentLeft;
        
        _customerName.textColor = Color(0x000000);
        
        [self addSubview: imageView];
        [self addSubview: _customerName];
    }
    return _customerName;
}

- (UILabel *)customerPhone{
    
    if(!_customerPhone){
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.carType.rightEdge+ActualWidth(20), ActualHeight(20), ActualWidth(40), ActualHeight(40))];
        imageView.image = [UIImage imageNamed:Appointment_Customer];
        
        _customerPhone = [[UILabel alloc]initWithFrame:CGRectMake(imageView.rightEdge+10, self.customerName.bottomEdge,ActualWidth(145), ActualHeight(34))];
        _customerPhone.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _customerPhone.textAlignment = NSTextAlignmentLeft;
        
        _customerPhone.textColor = Color(0x666666);
        
        [self addSubview: _customerPhone];
        
        //分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.carType.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        
        [self addSubview:view];
        
    }
    return _customerPhone;

}
- (UIButton *)btnPreview{
    
    if(!_btnPreview){
        
        _btnPreview = [[UIButton alloc]initWithFrame:CGRectMake(self.customerPhone.rightEdge+ActualWidth(50), ActualHeight(15), ActualWidth(50), ActualHeight(55))];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(ActualWidth(10), 0, ActualHeight(30), ActualWidth(30))];
        imageView.image = [UIImage imageNamed:Common_Preview];
        [_btnPreview addSubview:imageView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, imageView.bottomEdge+5, ActualWidth(50), ActualHeight(20))];
        [_btnPreview addSubview:label];
        label.text = @"预览";
        label.textColor = TitleColor;
        label.textAlignment = NSTextAlignmentCenter;
        [_btnPreview addSubview:label];
        [self addSubview: _btnPreview];
        
        [_btnPreview addTarget:self action:@selector(didClickPreviewButton) forControlEvents:UIControlEventTouchUpInside];
        //右侧分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.customerPhone.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        
        [self addSubview:view];
    
    }
    return _btnPreview;

}
- (void)didClickPreviewButton{
    
    NSIndexPath *indexPatch = [((UITableView *)self.superview.superview) indexPathForCell:self];
    
    if([self.delegate respondsToSelector:@selector(didClickPreViewWithIndex:)]){
    
        [self.delegate didClickPreViewWithIndex:indexPatch];
    }

}

#pragma mark 根据model赋值
- (void)updateDataWithModel:(ICMProxySearchModel *)model{
    self.contentView.backgroundColor = Color(0xF1F3F3);
    self.assistantName.text = model.assistantName;
    self.assistantPhone.text = model.assistantPhone;
    self.plateNum.text = model.plateNum;
    self.creatDate.text = [ICrEAMTool getDateWithTimeInterval:model.creatDate];
    
    self.proxyType.text = [ICrEAMTool getCodeModelForCode:model.proxyType].desc;
    self.proxyID.text = model.proxyID;
    self.carType.text = model.carType;
    self.customerName.text = model.customerName;
    self.customerPhone.text = model.customerPhone;
    self.btnPreview.hidden = NO;
    
}
@end
